<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2018/5/30
 * Time: 下午1:42
 */

namespace App\Modules\Shop\Models;


use Illuminate\Database\Eloquent\Model;

class Products extends Model
{

    protected $table = 'products';
    protected $fillable = ['id','product_name','category_id','category_name','images','img_thum','desc','promise','detail','ship_fee_temp','status','created_at','updated_at','vip_month','paid_num'];

    public function product_specific() {
        return $this->hasMany(ProductSpecifiction::class,'product_id','id');
    }

    public function ship_fee_template() {
        return $this->belongsTo(ShipFeeTemplate::class,'ship_fee_temp');
    }

    public function category() {
        return $this->belongsTo(GoodsCategories::class,'category_id','id');
    }

    public static function addProduct($data) {
        return self::create($data);
    }

    public static function updateProduct($id,$data) {
        return self::where('id',$id)->update($data);
    }

    public static function deleteProducts($id) {
        return self::where('id',$id)->update(['status'=>-1]);
    }
}